﻿@model ProductModel

@using Telerik.Web.Mvc.UI;
@if (Model.Id > 0)
{     
    <table class="adminContent">
        <tr>
            <td>
                <ul>
                    <li>
                        @T("Admin.Catalog.Products.AssociatedProducts.Note1")
                    </li>
                    <li>
                        @T("Admin.Catalog.Products.AssociatedProducts.Note2")
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                @(Html.Telerik().Grid<ProductModel.AssociatedProductModel>()
                .Name("associatedproducts-grid")
                    .DataKeys(keys =>
                    {
                        keys.Add(x => x.Id);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax()
                            .Select("AssociatedProductList", "Product", new { productId = Model.Id })
                            .Update("AssociatedProductUpdate", "Product")
                            .Delete("AssociatedProductDelete", "Product");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.ProductName)
                            .ReadOnly();
                        columns.Bound(x => x.DisplayOrder)
                            .Centered();
                        columns.Bound(x => x.Id)
                            .Template(x => Html.ActionLink(T("Admin.Common.View").Text, "Edit", "Product", new { id = x.Id }, new { }))
                            .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Product/Edit/") + "<#= Id #>\">" + T("Admin.Common.View").Text + "</a>")
                            .Title(T("Admin.Common.View").Text)
                            .ReadOnly();
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                        });
                    })
                    .EnableCustomBinding(true))
            </td>
        </tr>
        <tr>
            <td width="100%">
                <input type="submit" id="btnAddNewAssociatedProduct" name="btnAddNewAssociatedProduct" value="@T("Admin.Catalog.Products.AssociatedProducts.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("AssociatedProductAddPopup", "Product", new { productId = Model.Id, btnId = "btnRefreshAssociatedProducts", formId = "product-form" }))    ', 800, 800, true); return false;" class="t-button" />
                <input type="submit" id="btnRefreshAssociatedProducts" name="btnRefreshAssociatedProducts" style="display: none" />
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('#btnRefreshAssociatedProducts').click(function () {
                            //refresh grid
                            var optionsGrid = $("#associatedproducts-grid");
                            optionsGrid.data('tGrid').ajaxRequest();

                            //return false to don't reload a page
                            return false;
                        });
                    });
                </script>
            </td>
        </tr>
    </table>
}
else
{
    @T("Admin.Catalog.Products.AssociatedProducts.SaveBeforeEdit")
}